package com.itheima.service.impl;

import com.itheima.mapper.BookCategoryMapper;
import com.itheima.pojo.BookCategory;
import com.itheima.service.BookCategoryService;
import com.itheima.utils.ThreadLocalUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class BookCategoryImpl implements BookCategoryService{
    @Resource
    public BookCategoryMapper bookCategoryMapper;
    @Override
    public void addBookCategory(BookCategory bookCategory) {
        bookCategory.setCreateTime(LocalDateTime.now());
        bookCategory.setUpdateTime(LocalDateTime.now());

        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        bookCategory.setCreateUser(userId);
        bookCategoryMapper.addBookCategory(bookCategory);
    }

    @Override
    public List<BookCategory> listBookCategry() {
        List<BookCategory> bookCategoryList=bookCategoryMapper.listBookCategry();
        return bookCategoryList;
    }

    @Override
    public void updateBookCategory(BookCategory bookCategory) {

        bookCategory.setUpdateTime(LocalDateTime.now());
        bookCategoryMapper.updateBookCategory(bookCategory);
    }

    @Override
    public void deleteBookCategory(Integer id) {
        bookCategoryMapper.deleteBookCategory(id);
    }

    @Override
    public BookCategory getById(Integer id) {
        BookCategory bookCategory=bookCategoryMapper.findById(id);
        return bookCategory;
    }
}
